import { request } from "@/utils/http";
import type { GetInfoResponse, LoginResponse } from "./model/userTypes";

// 登录
export const reqLogin = (username: string, password: string) => {
  // <any, string>的第一个类型为any即可，实际不会用上
  // 第二个类型是返回值数据中data的类型，根据接口文档填写
  return request.post<any, LoginResponse>("/admin/acl/index/login", {
    username,
    password,
  });
};

// 登出
export const reqLogout = () => {
  return request.post<any, null>("/admin/auth/index/logout");
};

// 查询用户信息
export const reqGetInfo = () => {
  return request.get<any, GetInfoResponse>("/admin/acl/index/info");
};

// 获取用户分页列表
export const reqPageList = (page: number, limit: number) =>
  request.get<any, any>(`/admin/acl/user/${page}/${limit}`);
// 查询获取用户分页列表(查询按钮)
export const reqNewPgeList = (page: number, limit: number, username: string) =>
  request.get<any, any>(
    `/admin/acl/user/${page}/${limit}/?username=${username}`
  );
//添加新的角色与修改已有的角色
export const reqAddOrUpdateUser = (data: any) => {
  //修改品牌
  if (data.id) {
    return request.put("/admin/acl/user/update", data);
  } else {
    //新增品牌
    return request.post("/admin/acl/user/save", data);
  }
};

// 删除数据接口
export const reqDeleteUser = (id: any) =>
  request.delete(`/admin/acl/user/remove/${id}`);

// 根据用户获取角色数据
export const reqtoAssign = (userId: any) =>
  request.get(`/admin/acl/user/toAssign/${userId}`);

// 根据用户分配角色
export const reqdoAssogn = (userId: any, roleId: any) =>
  request.post(`/admin/acl/user/doAssign?userId=${userId}&roleId=${roleId}`);

//获取用户信息
  export const reqRoles = (userId:any) => {
    return request.get<any,any>(`/admin/acl/user/toAssign/${userId}`);
  };
//提交请求
  export const reqDoAssign = (userId:any,roleId:any)=>{
      return request({
          url:`/admin/acl/user/doAssign`,
          method:'post',
          params:{
              userId,
              roleId
          }
      })
  }